package testweakreference;

import java.lang.ref.WeakReference;

public class UseWeakReference {

    public static void main(String[] args) {
        Salad salad = new Salad(new Apple());
        System.out.println(salad.get());
        System.gc();
        System.out.println(salad.get());

    }




}

class Apple{


}


class Salad extends WeakReference<Apple> {


    /**
     * Creates a new weak reference that refers to the given object.  The new
     * reference is not registered with any queue.
     *
     * @param referent object the new weak reference will refer to
     */
    public Salad(Apple referent) {
        super(referent);
    }
}
